<template>
  <div class="login-page">
    <el-card class="el-card">
      <template #header>黑马面经运营后台</template>
      <el-form label-width="100px" class="demo-ruleForm" :model="form" :rules="rules" ref="form">
        <el-form-item label="用户名:" prop="username">
          <el-input placeholder="请输入用户名" v-model="form.username" clearable>
          </el-input>
        </el-form-item>

        <el-form-item label="密码:" prop="password">
            <el-input placeholder="请输入密码" v-model="form.password" show-password></el-input>
        </el-form-item>
        <el-form-item>
            <el-button type="primary" @click="login" >登录</el-button>
          <el-button @click="reset">重置</el-button>
        </el-form-item>
      </el-form>
    </el-card>
  </div>
</template>
  
<script>

import { mapActions } from 'vuex';
export default {
  name: "login-page",
  data() {
    return {
      form: {
        username: "",
        password: "",
      },
      rules: {
        username: [
          { required: true, message: '请输入用户名', trigger: ['blur', 'change'] },
          { min: 5, max: 11, message: '长度在 5 到 11 个字符', trigger: ['blur', 'change'] }
        ],
        password: [
          { required: true, message: '请输入密码', trigger: ['blur', 'change'] },
          { pattern: /^\w{5,11}$/, message: '请输入 5 到 10 位的密码', trigger: ['blur', 'change'] }
        ]
      }
    }
  },
  methods: {
    ...mapActions('user',['loginAction']),
    //检验表单是否合法
    async login() {
      try {
        const valid = await this.$refs.form.validate();
        console.log(valid);
        if (valid) {
         await this.loginAction(this.form)
         this.$message.success('登录成功')
         this.$router.push('/dashboard')
        }
      } catch (e) {
        console.log(e);
      }
    },
  reset () {
    this.$refs.form.resetFields()
  }
}
};
</script>
  
<style lang="scss" scoped>
.login-page {
  min-height: 100vh;
  background: linear-gradient(-45deg, #ee7752, #e73c7e, #23a6d5, #23d5ab);
  background-size: 400% 400%;
  background-blend-mode: overlay;
  background-image: url(@/assets/login-bg.svg);
  background-repeat: no-repeat;
  background-position: center;
  background-size: cover;
  display: flex;
  align-items: center;
  justify-content: center;
  animation: gradientBG 15s ease infinite, fadeIn 0.5s ease;

  @keyframes gradientBG {
    0% {
      background-position: 0% 50%;
    }
    50% {
      background-position: 100% 50%;
    }
    100% {
      background-position: 0% 50%;
    }
  }

  @keyframes fadeIn {
    from {
      opacity: 0;
      transform: translateY(20px);
    }
    to {
      opacity: 1;
      transform: translateY(0);
    }
  }

  .el-card {
    width: 420px;
    background: rgba(255, 255, 255, 0.9);
    border-radius: 15px;
    box-shadow: 0 8px 32px 0 rgba(31, 38, 135, 0.37);
    backdrop-filter: blur(4px);
    border: 1px solid rgba(255, 255, 255, 0.18);
    transition: transform 0.3s ease;
    
    &:hover {
      transform: translateY(-5px);
    }

    ::v-deep .el-card__header {
      height: 80px;
      line-height: 40px;
      background: linear-gradient(135deg, rgba(183, 148, 244, 1) 0%, rgba(210, 190, 244, 1) 100%);
      text-align: center;
      color: #fff;
      font-size: 18px;
      border-radius: 15px 15px 0 0;
      animation: colorShift 5s infinite alternate;
    }
  }

  .el-form {
    padding: 0 20px;
    
    .el-form-item {
      margin-bottom: 25px;
      
      ::v-deep .el-form-item__label {
        color: #7e57c2;
      }
    }

    .el-button {
      transition: all 0.3s ease;
      
      &.el-button--primary {
        background: linear-gradient(135deg, rgba(183, 148, 244, 1) 0%, rgba(210, 190, 244, 1) 100%);
        border: none;
        color: white;
        
        &:hover {
          transform: translateY(-2px);
          box-shadow: 0 5px 15px rgba(183, 148, 244, 0.4);
        }
      }
      
      &:not(.el-button--primary) {
        background: rgba(245, 245, 255, 1);
        border-color: rgba(228, 224, 255, 1);
        color: #7e57c2;
        
        &:hover {
          background: rgba(235, 235, 255, 1);
          transform: translateY(-2px);
        }
      }
      
      &:active {
        transform: translateY(0);
      }
    }
  }
}

@keyframes colorShift {
  0% {
    background: linear-gradient(135deg, rgba(183, 148, 244, 1) 0%, rgba(210, 190, 244, 1) 100%);
  }
  50% {
    background: linear-gradient(135deg, rgba(210, 190, 244, 1) 0%, rgba(183, 148, 244, 1) 100%);
  }
  100% {
    background: linear-gradient(135deg, rgba(183, 148, 244, 1) 0%, rgba(210, 190, 244, 1) 100%);
  }
}
</style>
